package com.bdzt.phone.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.bdzt.phone.R;
import com.bdzt.phone.fragment.MyFragment;
import com.bdzt.phone.fragment.Step1Fragment;

import java.util.ArrayList;
import java.util.List;

public class IndexActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView tv_base_title;
    private FrameLayout fl_base_context;
    private RadioGroup rg_base_bottom;
    private RadioButton rb_but01, rb_but02;
    private List<Fragment> list;
    private  FragmentManager manager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        init();
        rb_but01.setChecked(true);


    }


    private void init() {
        list=new ArrayList<>();

        list.add(new Step1Fragment());
        list.add(new MyFragment());

        tv_base_title = (TextView) findViewById(R.id.tv_base_title);
        fl_base_context = (FrameLayout) findViewById(R.id.fl_base_context);
        rg_base_bottom = (RadioGroup) findViewById(R.id.rg_base_bottom);
        rb_but01 = (RadioButton) findViewById(R.id.rb_but01);
        rb_but02 = (RadioButton) findViewById(R.id.rb_but02);


        rb_but01.setOnClickListener(this);
        rb_but02.setOnClickListener(this);

        manager = this.getSupportFragmentManager();
        manager.beginTransaction().replace(R.id.fl_base_context,list.get(0)).commit();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rb_but01:
                manager.beginTransaction().replace(R.id.fl_base_context,list.get(0)).commit();
                break;
            case R.id.rb_but02:
                manager.beginTransaction().replace(R.id.fl_base_context,list.get(1)).commit();
                break;
        }
    }
}
